home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / comm / dlg / StoryInteracti.lha / StoryInteractive / StoryI.rexx < prev    next >
OS/2 REXX Batch file  |  1997-04-23  |  16KB  |  534 lines

  1. /******************************************************************
  2.  * Story Interactive V1.2 --- I got messy again.                  *
  3.  * Support: Noah Cunningham (cyberguy@dixie-net.com)              *
  4.  $VER: Story Interactive 1.2 -by- Noah Cunningham
  5.  ******************************************************************/
  6.  
  7. OPTIONS failat 10        /* fail at 10 */
  8. CALL PRAGMA('W','NULL')  /* DISABLE REQUESTORS.. IMPORTANT IN CASE DOORS:
  9.                             ISN'T ASSIGNED! */
  10. /* Pre-define a couple of vars to save time */
  11.  
  12. bs = X2C(8) || " " || X2C(8)
  13. yes_to_more = "Y" || bs || bs || bs || bs || bs || bs || bs || bs || bs || bs || bs || bs || bs
  14.  
  15. /* Get command line arguments & open the port */
  16.  
  17.   PARSE ARG port', 'sysop', 'user','level
  18.   port = port || ':'
  19.   CALL open(userport,port)
  20.  
  21. /* check if logfile exists.. if not make one. */
  22.  
  23.   IF ~EXISTS('LOGS:StoryInteractive.LOG') THEN DO
  24.      CALL OPEN(log,'LOGS:StoryInteractive.LOG','W')
  25.      WRITELN(log,"*****************************************************************")
  26.      WRITELN(log,"*** Story Interactive Logfile  ---  V1.2                      ***")
  27.      WRITELN(log,"*****************************************************************")
  28.      WRITELN(log,"")
  29.   END
  30.   CALL CLOSE(log)
  31.  
  32. /* Display Title */
  33. IF EXISTS("doors:StoryInteractive/Title.ans") THEN DO
  34.   CALL OPEN(disp,"doors:StoryInteractive/Title.ans",'R')
  35.   DO WHILE ~EOF(disp)
  36.     a = readln(disp)
  37.     say a
  38.   END
  39.   CALL CLOSE(disp)
  40.   a = readch(userport)
  41. END
  42.  
  43. /* Main Routine - Nice and neat */
  44.  
  45.   DO forever
  46.  
  47.     CALL DispMenu
  48.     WRITECH(userport,"Enter your selection: ")
  49.     selection = READCH(userport,1)
  50.     IF selection = 1 THEN DO
  51.       SAY "1 -- Read Story"
  52.       CALL ReadStory
  53.     END
  54.     IF selection = 2 THEN DO
  55.       SAY "2 -- Add to the story"
  56.       CALL AddToStory
  57.     END
  58.     IF selection = 3 THEN DO
  59.       SAY "3 -- Send Feedback"
  60.       CALL Feedback
  61.     END
  62.     IF selection = 4 THEN DO
  63.       SAY "4 -- Quit"
  64.       CALL Quit
  65.     END
  66.     IF selection = 5 THEN DO
  67.       SAY "5 -- Info"
  68.       call News
  69.     END
  70.     IF selection = 6 & level > 250  THEN DO
  71.       SAY "6 -- Sysop Menu"
  72.       CALL SysopMenu
  73.     END
  74.   END
  75.  
  76. SAY "This should NEVER be seen... If so, Noah's made a bonehead move."
  77. EXIT(10)
  78.  
  79.  
  80. DispMenu:
  81.  
  82. /* Does an alternate file exists?  If so load it. */
  83.  
  84. IF EXISTS("DOORS:StoryInteractive/MainMenu.ans") THEN DO
  85.   CALL OPEN(disp,"Doors:StoryInteractive/MainMenu.ans",'R')
  86.   DO WHILE ~EOF(disp)
  87.     a = readln(disp)
  88.     say a
  89.   END
  90.   CALL CLOSE(disp)
  91. END
  92.  
  93. /* If not.. display generic menu. */
  94.  
  95. ELSE DO
  96.   SAY "                                                         "
  97.   SAY "                                                         "
  98.   SAY "                            Story Interactive!           "
  99.   SAY "                            `'`'`'`'`'`'`'`'`'           "
  100.   SAY "                   oOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOo  "
  101.   SAY "                   [o] 1.) Read The Current Story   [o]  "
  102.   SAY "                   [o] 2.) Add to The Current Story [o]  "
  103.   SAY "                   [o] 3.) Feedback/Suggestions     [o]  "
  104.   SAY "                   [o] 4.) Quit                     [o]  "
  105.   SAY "                   [o] 5.) New Features List        [o]  "
  106.   IF level >250 THEN SAY "                   [o] 6.) Sysop Menu               [o]  "
  107.   SAY "                   [o]                              [o]  "
  108.   SAY "                   [o]          Version 1.2         [o]  "
  109.   SAY "                   [o]          ------- `-'         [o]  "
  110.   SAY "                   [o]      By: Noah Cunningham     [o]  "
  111.   SAY "                   oOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOo  "
  112.   SAY "                                                         "
  113. END
  114.   RETURN
  115.  
  116.  
  117.  
  118. /*****************************************************
  119.  ** More prompt... called after 23 lines of display **
  120.  *****************************************************/
  121. More:
  122.  
  123.   /* Setup erase-the-prompt using the backspace character and a spacebar */
  124.  
  125.   answer = ""
  126.  
  127.   WRITECH(userport,"[More? Y/n] ")
  128.   answer = READCH(userport,1)
  129.   IF answer = "N" | answer = "n" THEN DO
  130.     SAY "Nope!"
  131.     /* Return 1 if user said No */
  132.     RETURN(1)
  133.   END
  134.   WRITECH(userport,yes_to_more)
  135.   DROP answer
  136.   /* Return 0 is user said Yes */
  137.   RETURN(0)
  138.  
  139. /************************************************
  140.  ** Read the story.  And call the more prompt. **
  141.  ************************************************/
  142.  
  143. ReadStory:
  144.  
  145.   /* Variables needed by this function... */
  146.  
  147.   Count = 0   /* Count the lines */
  148.   Value = 0   /* Value returned by More prompt */
  149.   Done = 0    /* Boolean(spelling) variable -- 0 = not done, 1 = done */
  150.  
  151.   /* Read the current story and call More prompt when needed */
  152.  
  153.   CALL OPEN(story,'TEXT:StoryInteractive.txt','R')
  154.   DO WHILE Done = 0
  155.  
  156.    Count = Count + 1
  157.    Text = READLN(story)
  158.    SAY Text
  159.    IF Count = 23 THEN Value = More()
  160.    IF Count = 23 THEN Count = 0
  161.    Rtn = EOF(Story)
  162.    IF Rtn ~= 0 THEN Done = 1
  163.    IF Value = 1 THEN DO
  164.      /* If user responded no to more prompt... close her up. */
  165.      CALL CLOSE(story)
  166.       DROP Value
  167.       DROP Count
  168.       DROP Done
  169.       DROP Rtn
  170.      RETURN
  171.    END
  172.  
  173.   END
  174.   WRITECH(userport,"[Press Any Key]")
  175.   Rtn = READCH(userport,1)
  176.    DROP Rtn
  177.    DROP Value
  178.    DROP Count
  179.    DROP Done
  180.   CALL CLOSE(story)
  181.   RETURN
  182.  
  183.  
  184. AddToStory:     /**** Here's where I got messy again ****/
  185.  
  186. finished = 0
  187.  
  188. DO WHILE finished = 0
  189.   /* Variables needed by this function... */
  190.  
  191.   buf.0 = "NULL"
  192.   ch_number = 0
  193.   rc = D2C(10)
  194.   line_number = 1
  195.   line_of_text = ''
  196.   Done = 0          /* The beauty of being able to use the same word twice as */
  197.   DOne = 0          /* a variable by only changing the capitalization. */
  198.  
  199.   /* Add to the current story */
  200.  
  201.   CALL OPEN(log,'LOGS:StoryInteractive.log','A')
  202.   SAY ''
  203.   SAY '---Add To Current Story-------------------------------------------------------'
  204.   SAY 'Enter as many lines as you need.'
  205.   SAY '***** Hit Ctrl-Z on A NEW LINE when finished *****'
  206.   SAY '------------------------------------------------------------------------------'
  207.   WRITECH(userport,line_number || "> ")
  208.   DO WHILE Done = 0
  209.     ch = READCH(userport,5)
  210.     IF ch = "" THEN Done = 1
  211.     a = RIGHT(ch,1)
  212.     IF a ~= D2C(13) THEN WRITECH(userport,ch)
  213.  
  214. /* Here's a nice MESS... where I tried for days to figure out how to get rid
  215.    of the backspace key!  Thanks Basil! */
  216.  
  217.     line_of_text = line_of_text || ch
  218.     actual_text = COMPRESS(line_of_text,X2C(08))
  219.  
  220.     g = length(actual_text)            /* I got so tired I decided to goto */
  221.     h = length(line_of_text)           /* using letters as variables!      */
  222.  
  223.     i = g - (h - g)     /* <- A simple calculation that cuased days of pain. */
  224.  
  225. /* Thank god I finally did it! */
  226.  
  227.     IF i > 75 | a = D2C(13) THEN do
  228.       SAY ""
  229.       buf.line_number = line_of_text
  230.       top_of_buf = line_number
  231.       line_of_text = ""
  232.       line_number = line_number + 1
  233.       WRITECH(userport,line_number || "> ")
  234.     END
  235.  
  236.   END
  237.  
  238. /* Okay the user has finished... Now we go back through and check if he/she
  239.    typed backspace any, and we take out the boo-boos. */
  240.  
  241.   a = 1; temp_counter = 0
  242.  
  243.   DO while temp_counter < top_of_buf
  244.  
  245.     temp_counter = temp_counter + 1
  246.     l_t = buf.temp_counter
  247.     DO while POS(X2C(08),l_t) ~= 0
  248.       a = POS(X2C(08),l_t) - 1
  249.       l_t = DELSTR(l_t,a,2)
  250.     END
  251.     buf.temp_counter = l_t
  252.   END
  253.  
  254.   SAY ""
  255.   SAY "********************************* Your Entry ********************************"
  256.   SAY ""
  257.   temp_counter = 0
  258.   DO WHILE temp_counter < top_of_buf
  259.  
  260.     temp_counter = temp_counter + 1
  261.     SAY buf.temp_counter
  262.  
  263.   END
  264.   CALL CLOSE(story)
  265.   answer = ''
  266.   WRITECH(userport,"[ [Y] Yes -- Add,  [R] Re-do,  [A] Abort ]  ->")
  267.   answer = READCH(userport)
  268.   /* If user says yes, save his entry, add to the logs, nd add to the story. */
  269.   IF answer = 'Y' | answer = 'y' | answer = '' | answer = D2C(13) THEN DO
  270.     SAY 'Yes!'
  271.     CALL OPEN(story,'TEXT:StoryInteractive.txt','A')
  272.     WRITELN(log,'*** (' user ') Added the following to the story ***')
  273.     temp_counter = 0
  274.     DO WHILE temp_counter < top_of_buf
  275.  
  276.       temp_counter = temp_counter + 1
  277.       line_text = buf.temp_counter
  278.       ret = WRITELN(story,line_text)
  279.       ret = WRITELN(log,line_text)
  280.  
  281.     END
  282.     CALL CLOSE(story)
  283.     CALL CLOSE(log)
  284.      DROP Done
  285.      DROP line_of_text
  286.      DROP Line_Number
  287.      DROP Rtn
  288.     SAY ''
  289.     SAY 'Added to the story!'
  290.     finished = 1
  291.     RETURN
  292.   END
  293.   ELSE IF answer = 'A' | answer = 'a' | answer = 'n' | answer = 'N' THEN DO
  294.     address command 'delete RAM:StoryInteractive.txt'
  295.     SAY "Abort!"
  296.     RETURN
  297.   END
  298.   ELSE IF answer = 'R' | answer = 'r' THEN SAY 'Redo!'
  299.   ELSE SAY "Invalid response... Assuming you meant redo."
  300. END
  301. RETURN
  302.  
  303. /*********************************************************
  304.  ** Send feedback.  Only DLG could make it this simple. **
  305.  *********************************************************/
  306.  
  307. Feedback:
  308.  
  309.   /* Variables needed by this function... */
  310.  
  311.   line_of_text = ""
  312.   line_number = 1
  313.   Done = 0
  314.  
  315.   /* I haven't went to great lengths to make this work like I have the
  316.      Add-to-story function.  This creates messages merely by shoving a big
  317.      long line of text into a file and using SendMSG to send it to the sysop.
  318.      The message on the other end won't have the correct ends of lines, but
  319.      he'll get the message. */
  320.  
  321.   SAY ''
  322.   SAY '---Feedback-------------------------------------------------------'
  323.   SAY 'This will be sent to your sysop as private mail on the BBS in the '
  324.   SAY 'mail system.  Press Ctrl-Z when finished.                         '
  325.   SAY '------------------------------------------------------------------'
  326.   CALL OPEN(msg,'RAM:Feedback.tmp','W')
  327.   WRITECH(userport,line_number || "> ")
  328.   DO WHILE Done = 0
  329.     ch = READCH(userport,5)
  330.     IF ch = "" THEN Done = 1
  331.     a = RIGHT(ch,1)
  332.     IF a~= D2C(13) THEN WRITECH(userport,ch)
  333.     line_of_text = line_of_text || ch
  334.     IF length(line_of_text) > 75 | a = D2C(13) THEN do
  335.       SAY ""
  336.       WRITELN(msg,line_of_text)
  337.       line_of_text = ""
  338.       line_number = line_number + 1
  339.       WRITECH(userport,line_number || "> ")
  340.     end
  341.   END
  342.   SAY ""
  343.   SAY ""
  344.   WRITECH(userport,"Sending Message... ")
  345.   CALL CLOSE(msg)
  346.    DROP Done
  347.    DROP line_of_text
  348.    DROP Line_Number
  349.    DROP Rtn
  350.   ADDRESS COMMAND 'DLG:SendMSG -f "' || user || '" -s "Story Interactive" -b RAM:Feedback.tmp -r "' || sysop || '" >NIL:'
  351.   ADDRESS COMMAND 'Delete RAM:Feedback.tmp'
  352.   SAY "Sent!"
  353.   RETURN
  354.  
  355.  
  356. Quit:
  357.   SAY ""
  358.   WRITECH(userport,"Leaving So Soon? [Y,n] ")
  359.   answer = READCH(userport,1)
  360.   IF answer = 'N' ^ answer = 'n' THEN DO
  361.     SAY "No!"
  362.     RETURN
  363.   END
  364.     SAY "Yes."
  365.     SAY ""
  366.   EXIT
  367.  
  368.  
  369. SysopMenu:
  370.  
  371.   Done = 0
  372.  
  373.   WRITECH(userport,X2C('1B') || "[2J" || X2C('1B') || "[H")
  374.                 /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ clear screen */
  375.  
  376.   DO while Done = 0
  377.     SAY ''
  378.     SAY 'Sysop Menu'
  379.     SAY '=========='
  380.     SAY ''
  381.     SAY '1. Start New Story'
  382.     SAY '2. View logs'
  383.     SAY '3. Return to Main Menu'
  384.     SAY ''
  385.     WRITECH(userport,"Enter your selection," user || ": ")
  386.     selection = READCH(userport,1)
  387.     IF selection = 1 THEN do
  388.       SAY '1 -- Start New Story'
  389.       CALL NewStory
  390.     end
  391.     IF selection = 2 THEN do
  392.       SAY '2 -- View Logs'
  393.       CALL ViewLogs
  394.     end
  395.     IF selection = 3 THEN do
  396.       SAY "3 -- Return to Main Menu"
  397.       SAY ""
  398.       Done = 1
  399.     end
  400.   END
  401.   selection = 0
  402.   RETURN
  403.  
  404. News:
  405.   SAY "Story Interactive v1.2"
  406.   SAY "======================"
  407.   say ""
  408.   say "Story Interactive keeps track of a story that users can contribute their"
  409.   say "ideas to.  These stories can end up funny, scary, dirty, or who knows what"
  410.   say "depending on the imaginations of the users!"
  411.   say ""
  412.   say "Story Interactive is so simple to use I don't even think insturctions are"
  413.   say "needed.  But for those of us who are less fortunate upstairs--here are the"
  414.   say "instructions."
  415.   say ""
  416.   say "#1 on the main menu will let you read the currently running story. I would"
  417.   say "recommend doing this before adding to the story so you know what the story"
  418.   say "is about."
  419.   say "#2 on the main menu will let you contribute your ideas to the story. When"
  420.   say "adding to the story you will not be able to backup a line, so be careful"
  421.   say "as you type.  You can backspace as much as you need on the current line, "
  422.   say "but once you hit return or you reach the end of the line and are wrapped"
  423.   say "down to the next line you may not go back to the previous line.  When you"
  424.   say "finish your entry press Control and Z and you'll be prompted with a save"
  425.   say "prompt...  [Y,r,a] -- Yes (accept), Redo, Abort (forget it!)"
  426.   Say "[PRESS RETURN]"
  427.   a = readch(userport)      /* ... A crappy little return prompt */
  428.   say "#3 on the main menu will allow you to send feedback to the sysop about the"
  429.   say "current story, or any bugs you might run into."
  430.   say "#4 on the main menu will allow you to exit Story Interactive."
  431.   say "#5 is this information screen."
  432.   say ""
  433.   say "Contacting the author"
  434.   say "====================="
  435.   say ""
  436.   say " Internet: cyberguy@dixie-net.com"
  437.   say "      BBS: The Cyber Zone (601) 728-0306"
  438.   say "  Fidonet: <not available>"
  439.   say ""
  440.   say " I hope you have fun and enjoy Story Interactive!!!"
  441.   say ""
  442.   say "[PRESS RETURN]"
  443.   a = readch(userport)
  444.   RETURN
  445.  
  446.  
  447. /************************************
  448.  ** New Story function for sysops. **
  449.  ************************************/
  450.  
  451. NewStory:
  452.  
  453.   done = 0
  454.   title = ""
  455.  
  456.   SAY ""
  457.   WRITECH(userport,'Enter title for new story: ')
  458.   DO while done = 0
  459.     ch = READCH(userport,5)
  460.     title = title || ch
  461.     a = RIGHT(ch,1)
  462.     IF a ~= D2C(13) THEN WRITECH(userport,ch)
  463.     IF a = D2C(13) THEN done = 1
  464.   END
  465.   r_title = title
  466.   SAY ""
  467.  
  468.  /* My own little procedure for centering the title... CENTER() was cutting
  469.      off the first letter sometimes. (???) */
  470.  
  471.     e = ""                     /* <cackle> here I went back to alphabetic */
  472.     b = LENGTH(title)          /* variables again. */
  473.     c = 78 - b
  474.     d = .50 * c
  475.     do while length(e) < d
  476.       e = e || " "
  477.     end
  478.     DROP b
  479.     DROP c
  480.     DROP d
  481.     title = e || title || D2C(13)
  482.  
  483.   /* Nice, huh? :) */
  484.  
  485.   /* Okay.. here we move the old story... make new file with new title, and
  486.      make new logfile for this story. */
  487.  
  488.   SAY "Old Story being moved to LOGS:SI.txt_old..."
  489.   address command 'copy Text:StoryInteractive.txt logs:SI.txt_old'
  490.   address command 'delete TEXT:StoryInteractive.txt'
  491.   SAY "Creating New file..."
  492.   CALL OPEN(story,'TEXT:StoryInteractive.txt','W')
  493.   SAY "Writing header/title..."
  494.   WRITELN(story,"***************************************************************************")
  495.   WRITELN(story,"")
  496.   WRITELN(story,title)
  497.   WRITELN(story,"")
  498.   CALL CLOSE(story)
  499.   SAY "Making new logfile... Old one can be found as LOG:SI.log_old "
  500.   ADDRESS COMMAND "copy logs:StoryInteractive.log logs:SI.log_old"
  501.   CALL OPEN(log,"LOGS:StoryInteractive.log",'W')
  502.   WRITELN(log,"**************************Story Interactive Logfile************************")
  503.   WRITELN(log,"<SYSTEM> New story -- " r_title)
  504.   CALL CLOSE(log)
  505.   SAY "Done!"
  506.   RETURN
  507.  
  508.  
  509. /********************
  510.  ** View the logs. **
  511.  ********************/
  512.  
  513. ViewLogs:
  514.  
  515.   b = 0;c = 0
  516.   done = 0
  517.  
  518.   CALL OPEN(log,"LOGS:StoryInteractive.log",'R')
  519.   DO WHILE ~eof(log)
  520.     a = readln(log)
  521.     SAY a
  522.     b = b + 1
  523.     IF b = 23 THEN c = More()
  524.     IF c = 1 THEN DO
  525.       CALL CLOSE(log)
  526.       RETURN
  527.     END
  528.     IF b = 22 & c = 0 THEN b = 0
  529.   END
  530.   CALL CLOSE(log)
  531.   WRITECH(userport,"[PRESS ANY KEY]")
  532.   a = READCH(userport)
  533.   SAY ""
  534.   RETURN